//
//  NSObject+Helper.m
//  ChineseCollegeStudentsNetwork
//
//  Created by 魏苏扬 on 2018/8/11.
//  Copyright © 2018年 刘喆. All rights reserved.
//

#import "NSObject+Helper.h"

@implementation NSObject (Helper)
+ (NSString*)convertToObject:(id)object {
    if (isEmpty(object)) {
        return @"数据为空";
    }
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    NSString *jsonString = @"";
    
    if (!jsonData) {
        NSLog(@"Got an error: %@", error);
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    
    jsonString = [jsonString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];  //去除掉首尾的空白字符和换行字符
    
    [jsonString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    
    return jsonString;
}
@end
